home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / insight / plugins / mynegate.pro < prev    next >
Text File  |  1997-07-08  |  6KB  |  212 lines

  1. ; $Id: mynegate.pro,v 1.13 1997/04/22 16:21:58 rob Exp $
  2. ;
  3. ; Copyright (c) 1997, Research Systems, Inc.  All rights reserved.
  4. ;   Unauthorized reproduction prohibited.
  5. ;+
  6. ; FILE:
  7. ;       mynegate.pro
  8. ;
  9. ; PURPOSE:
  10. ;       This file contains an example Conditioning PlugIn that does negation.
  11. ;
  12. ; CONTENTS:
  13. ;       GENERAL ROUTINES
  14. ;           pro HandleEventsMyNegate    - handle dialog box events
  15. ;
  16. ;       CALLBACK ROUTINES
  17. ;           fun PromptUserMyNegate      - main entry point (creates dialog)
  18. ;
  19. ;       REGISTRATION FUNCTION
  20. ;           fun MyNegate                - registers the PlugIn
  21. ;
  22. ;-
  23.  
  24. ; *****************************************************************************
  25. ;       GENERAL ROUTINES
  26. ; *****************************************************************************
  27.  
  28. ; -----------------------------------------------------------------------------
  29. ;
  30. ;   Purpose:  Handle dialog events.
  31. ;
  32. pro HandleEventsMyNegate, sEvent
  33.  
  34.     ;  Catch errors.
  35.     ;
  36.     CATCH, error
  37.     if (error ne 0) then begin
  38.         CATCH, /CANCEL
  39.         void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=(*psState).wMainBase)
  40.         RETURN
  41.     endif
  42.  
  43.     ;  Grab the state pointer from the widget user value.
  44.     ;
  45.     WIDGET_CONTROL, sEvent.top, GET_UVALUE=psState
  46.  
  47.     ;  Get the parent widget ID.
  48.     ;
  49.     wParent = (*psState).wMainBase
  50.  
  51.     ; ========================
  52.     ;     PROCESS EVENTS
  53.     ; ========================
  54.  
  55.     case (sEvent.id) of
  56.  
  57.         ; --------------------------------------
  58.         ;     OK button
  59.         ; --------------------------------------
  60.         (*psState).wOKButton: begin
  61.  
  62.             ;  Get the type code.
  63.             ;
  64.             size = SIZE((*psState).data)
  65.             type = size[size[0] + 1]
  66.  
  67.             ;  Perform conditioning (negation) if the type is right.
  68.             ;
  69.             if ( ((type ge 1) and (type le 6)) or $
  70.                  (type eq 9) ) then begin
  71.  
  72.                 ;  Warn the user about byte data.
  73.                 ;
  74.                 if (type eq 1) then begin
  75.                     message = 'Byte data will be wrapped rather than negated.'
  76.                     void = DIALOG_MESSAGE(message, DIALOG_PARENT=wParent)
  77.                 endif
  78.  
  79.                 ;  Perform the negation.
  80.                 ;
  81.                 (*psState).data = - (*psState).data
  82.  
  83.                 ;  Set the update flag.
  84.                 ;
  85.                 (*psState).update = 1B
  86.  
  87.             endif else begin
  88.  
  89.                 ;  Tell the user this type is not supported.
  90.                 ;
  91.                 message = 'This type is not supported for negation.'
  92.                 void = DIALOG_MESSAGE(message, DIALOG_PARENT=wParent)
  93.  
  94.             endelse
  95.  
  96.             ;  Destroy the dialog box.
  97.             ;
  98.             WIDGET_CONTROL, sEvent.top, /DESTROY
  99.         end
  100.  
  101.         ; --------------------------------------
  102.         ;     Cancel button
  103.         ; --------------------------------------
  104.         (*psState).wCancelButton: begin
  105.  
  106.             ;  Destroy the dialog box.
  107.             ;
  108.             WIDGET_CONTROL, sEvent.top, /DESTROY
  109.         end
  110.  
  111.         ; --------------------------------------
  112.         ;     other events
  113.         ; --------------------------------------
  114.         else:   ; (do nothing)
  115.  
  116.     endcase
  117.  
  118. end                 ; HandleEventsMyNegate
  119.  
  120. ; *****************************************************************************
  121. ;       CALLBACK ROUTINES
  122. ; *****************************************************************************
  123.  
  124. ; -----------------------------------------------------------------------------
  125. ;
  126. ;   Purpose:  Main entry point for the PlugIn.
  127. ;
  128. function PromptUserMyNegate, $
  129.     data, $             ; IN/OUT: the data to condition
  130.     GROUP=wGroup, $     ; IN: the widget group leader
  131.     _EXTRA=extra        ; IN: (for unused keywords)
  132.  
  133.     ;  Create main base (non-sizable).
  134.     ;
  135.     title = 'Conditioning PlugIn Example - My Negate'
  136.     wMainBase = WIDGET_BASE(TITLE=title, GROUP_LEADER=wGroup, $
  137.         /COLUMN, /MODAL, /TLB_FRAME_ATTR)
  138.  
  139.     void = WIDGET_LABEL(wMainBase, VALUE='Negate the selected data.')
  140.  
  141.     ;  Create other widgets.
  142.     ;
  143.     wButtonBase = WIDGET_BASE(wMainBase, /ROW, /ALIGN_RIGHT)
  144.  
  145.     wOKButton      = WIDGET_BUTTON(wButtonBase, VALUE='   OK   ')
  146.     wCancelButton  = WIDGET_BUTTON(wButtonBase, VALUE=' Cancel ')
  147.  
  148.     ;  Create the dialog state.
  149.     ;
  150.     sState = { $
  151.         update: 0B, $
  152.         data: data, $
  153.         wMainBase: wMainBase, $
  154.         wOKButton: wOKButton, $
  155.           wCancelButton: wCancelButton $
  156.         }
  157.  
  158.     ;  Store the state in a heap variable,
  159.     ;  and the pointer in the widget user value.
  160.     ;
  161.     psState = PTR_NEW(sState, /NO_COPY)
  162.     WIDGET_CONTROL, wMainBase, SET_UVALUE=psState
  163.  
  164.     ;  Realize the dialog box.
  165.     ;
  166.     WIDGET_CONTROL, wMainBase, /REALIZE
  167.  
  168.     ;  Set modal widget default and cancel buttons.
  169.     ;
  170.     WIDGET_CONTROL, wMainBase, DEFAULT_BUTTON=wOKButton, $
  171.         CANCEL_BUTTON=wCancelButton
  172.  
  173.     ;  Start event loop.
  174.     ;
  175.     XMANAGER, 'PromptUserMyNegate', wMainBase, $
  176.         EVENT_HANDLER='HandleEventsMyNegate'
  177.  
  178.     ;  Grab the data and the 'update' flag, remove the state,
  179.     ;  and return the flag.
  180.     ;
  181.     data = (*psState).data
  182.     update = (*psState).update
  183.     PTR_FREE, psState
  184.     RETURN, update      ; (return 1 on success, 0 if nothing done)
  185.  
  186. end                 ; PromptUserMyNegate
  187.  
  188. ; *****************************************************************************
  189. ;       REGISTRATION FUNCTION
  190. ; *****************************************************************************
  191.  
  192. ; -----------------------------------------------------------------------------
  193. ;
  194. ;   Purpose:  Register the Conditioning PlugIn.
  195. ;
  196. function MyNegate
  197.  
  198.     ;  Return the Conditioning PlugIn Registration Structure.
  199.     ;
  200.     RETURN, { $
  201.         type:       'Conditioning_PlugIn', $        ; PlugIn type
  202.         title:      'My Negate...', $               ; PlugIn title
  203.         purpose:    'Reverse sign of data.', $      ; PlugIn purpose
  204.         main_func:  'PromptUserMyNegate', $         ; main callback
  205.         version:    '5.0', $                        ; IDL version
  206.         revision:   '1.0' $                         ; PlugIn version
  207.         }
  208.  
  209. end                 ; MyNegate
  210.  
  211. ; -----------------------------------------------------------------------------
  212.